package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/3/7 13:00
 * @description：https://leetcode-cn.com/problems/base-7/
 */
public class 七进制数 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.convertToBase7(-7));
    }

    class Solution {
        public String convertToBase7(int num) {
            if (num == 0) return "0";
            StringBuilder ans = new StringBuilder();
            boolean symbol = num > 0;
            num = Math.abs(num);
            while (num > 0) {
                ans.append(num % 7);
                num /= 7;
            }
            if (!symbol) {
                ans.append("-");
            }
            return ans.reverse().toString();
        }
    }
}
